package cn.schoolwow.workflow.module.definition.action.service;

import cn.schoolwow.quickdao.domain.DAO;
import cn.schoolwow.quickflow.domain.FlowContext;
import cn.schoolwow.quickflow.flow.BusinessFlow;
import cn.schoolwow.workflow.domain.deploy.WorkFlowDefinitionOption;
import cn.schoolwow.workflow.entity.WorkFlowDefinition;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;

public class UpdateWorkFlowDeployOptionServiceFlow implements BusinessFlow {
    @Override
    public void executeBusinessFlow(FlowContext flowContext) throws Exception {
        String name = flowContext.checkData("name", String.class);
        WorkFlowDefinitionOption workFlowDefinitionOption = flowContext.checkInstanceData(WorkFlowDefinitionOption.class);
        DAO dao = flowContext.checkInstanceData(DAO.class);

        JSONObject option = JSON.parseObject(JSON.toJSONString(workFlowDefinitionOption));

        dao.query(WorkFlowDefinition.class)
                .addQuery("name", name)
                .addUpdate("option", option)
                .execute()
                .update();
    }

    @Override
    public String name() {
        return "更新工作流定义选项服务流程";
    }

}
